package com.wenwei.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wenwei.bean.HisPointBean;
import com.wenwei.parking.R;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/8/22.
 */
public class HistoryPoiAdapter extends RecyclerView.Adapter<HistoryPoiAdapter.MyViewHolder> {

    private ArrayList<HisPointBean> mList;

    public void setmList(ArrayList<HisPointBean> list) {
        this.mList = list;
    }

    public interface CallBack {
        void onItemClick(HisPointBean bean);
    }

    private CallBack mCallBack;

    public void setmCallBack(CallBack callBack) {
        this.mCallBack = callBack;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_history_poi, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.pointName.setText(mList.get(position).getParkName());
        holder.pointCode.setText("编号："+mList.get(position).getParkNum());
        holder.pointAddress.setText(mList.get(position).getParkAddress());
        holder.pointGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mCallBack!=null){
                    mCallBack.onItemClick(mList.get(position));
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.point_name)
        TextView pointName;
        @Bind(R.id.point_code)
        TextView pointCode;
        @Bind(R.id.point_address)
        TextView pointAddress;
        @Bind(R.id.point_go)
        LinearLayout pointGo;
        public MyViewHolder(View view) {

            super(view);
            ButterKnife.bind(this, view);
        }
    }


}
